package org.example.config;

import org.example.Interceptor.PermissionInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// 2. 注册拦截器
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private PermissionInterceptor permissionInterceptor;

    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(permissionInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(
                        // 原有排除：登录、退出
                        "/login",
                        // 1. Swagger UI 核心路径（匹配你访问的 /swagger-ui/index.html）
                        "/swagger-ui/**",
                        "/swagger-ui/index.html",
                        // 2. Swagger 资源配置路径
                        "/swagger-resources/**",
                        "/swagger-resources",
                        // 3. OpenAPI 3 文档数据路径（API 元数据接口）
                        "/v2/api-docs/**",
                        "/v2/api-docs.yaml",
                        // 4. Swagger 依赖的前端资源（如 webjars）
                        "/webjars/**"
                );
    }
}